package com.cfs.svcimpl.bz;

import java.util.List;

import com.cfs.dao.bz.AppInfoDao;
import com.cfs.po.bz.AppInfo;
import com.cfs.svc.bz.AppInfoService;
import com.cfs.vo.Condition;
import com.cfs.vo.Pager;
import com.cfs.vo.Res;



public class AppInfoServiceImpl implements AppInfoService {

	private AppInfoDao dao;
	
	public void setDao(AppInfoDao d){
		this.dao = d;
	}

	
	public AppInfo get(Long id) {
		AppInfo c = dao.get(id);
		return c;
	}

	
	public List<AppInfo> list(Condition c) {
		return dao.list(c);
	}

	
	public Integer deleteById(Long id) {
		return dao.delete(id);
	}

	public Long add(AppInfo c) {
		Long n = dao.insert(c);
		return c.getId();
	}

	
	public Long update(AppInfo app) {
		return dao.update(app);
	}

	
	public AppInfo latest(String app) {
		return dao.latest(app);
	}

	
	public List<AppInfo> listDid(String did) {
		return dao.listDid(did, null);
	}


	@Override
	public Res<AppInfo> listP(Condition c) {
		Res<AppInfo> res = new Res<AppInfo>();
		try{
			Pager p = c.getP() == null ? new Pager() : c.getP();
			p.resetTotalR(dao.queryRows(c));
			List<AppInfo> list = dao.list(c);

			res.setP(p);
			res.setList(list);

		}catch(Exception e){
			res.setCode(-1);
			res.setMsg(e.getLocalizedMessage());
			e.printStackTrace();
		}
		
		return res;
	}



}
